From: Florian Müllner Date: Wed, 20 Apr 2022 17:29:19 +0000 (+0200) Subject: extensionSystem: Check metadata types X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~480^2^2~27 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=56d0b6d8317cbb824e997ce6a926028788b11dc8;p=gnome-shell.git extensionSystem: Check metadata types We currently check that an extension provides required metadata properties, but then assume that all properties have the expected type. It turns out that this is putting too much trust in extensions, so add an appropriate check. https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5347 Part-of: --- diff --git a/js/ui/extensionSystem.js b/js/ui/extensionSystem.js index 41a03fdf3..fbfd6c4b0 100644 --- a/js/ui/extensionSystem.js +++ b/js/ui/extensionSystem.js @@ -310,11 +310,29 @@ var ExtensionManager = class { throw new Error(`Failed to parse metadata.json: ${e}`); } - let requiredProperties = ['uuid', 'name', 'description', 'shell-version']; + const requiredProperties = [{ + prop: 'uuid', + typeName: 'string', + }, { + prop: 'name', + typeName: 'string', + }, { + prop: 'description', + typeName: 'string', + }, { + prop: 'shell-version', + typeName: 'string array', + typeCheck: v => Array.isArray(v) && v.length > 0 && v.every(e => typeof e === 'string'), + }]; for (let i = 0; i < requiredProperties.length; i++) { - let prop = requiredProperties[i]; + const { + prop, typeName, typeCheck = v => typeof v === typeName, + } = requiredProperties[i]; + if (!meta[prop]) throw new Error(`missing "${prop}" property in metadata.json`); + if (!typeCheck(meta[prop])) + throw new Error(`property "${prop}" is not of type ${typeName}`); } if (uuid != meta.uuid)